package com.redsoil.house.ui.mine.fragment;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.redsoil.house.R;
import com.redsoil.house.base.RootFragment;
import com.redsoil.house.model.bean.ProductsVO;
import com.redsoil.house.model.bean.TestVO;
import com.redsoil.house.ui.capital.contract.CapitalContract;
import com.redsoil.house.ui.capital.presenter.CapitalPresenter;
import com.redsoil.house.ui.mine.activity.FoodsInfoActivity;
import com.redsoil.house.ui.mine.adapter.MineSpecialAdapter;
import com.redsoil.house.ui.mine.contract.MineSpecialContract;
import com.redsoil.house.ui.mine.presenter.MineSpecialPresenter;
import com.redsoil.house.ui.property.adapter.PropertyLeaseAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 资产主界面
 */
public class MineSpecialFragment extends RootFragment<MineSpecialPresenter> implements MineSpecialContract.View {

    @BindView(R.id.rv_list)
    RecyclerView rv_list;

    private MineSpecialAdapter mineSpecialAdapter;

    public static MineSpecialFragment newInstance() {
        Bundle args = new Bundle();

        MineSpecialFragment fragment = new MineSpecialFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void initEventAndData() {

        super.initEventAndData();

        stateLoading();

        mPresenter.postProducts();
    }

    @Override
    public void postProductsSuccess(ProductsVO productsVO) {
        //添加自定义分割线
        DividerItemDecoration divider = new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getContext(),R.drawable.mine_specail_list_divider));
        rv_list.addItemDecoration(divider);

//        rv_list.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));
        rv_list.setLayoutManager(new LinearLayoutManager(getContext()));


        mineSpecialAdapter = new MineSpecialAdapter(R.layout.mine_special_item,productsVO.getDataList());

        mineSpecialAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                ProductsVO.DataListBean dataListBean = (ProductsVO.DataListBean)adapter.getData().get(position);

                getContext().startActivity(FoodsInfoActivity.newInstance(getContext(),dataListBean.getId()));
            }
        });

        rv_list.setAdapter(mineSpecialAdapter);

        stateMain();
    }

    @Override
    public void responeError(String errorMsg) {
        stateError();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_mine_specail;
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }
}
